package Other;

public class leet_200 {
    public static void main(String[] args) {
        System.out.println();
    }
}


class Solution_200 {
    public int numIslands(char[][] grid) {
        int islandNum = 0;

        for(int i=0; i<grid.length; i++){
            for(int j=0; j<grid[0].length; j++){
                if(grid[i][j]=='1'){
                    dfs(grid, i, j);
                    islandNum++;
                }
            }
        }
        return islandNum;
    }

    void dfs (char[][] grid, int row, int col){
        if(row<0 || col<0 || row>grid.length-1 || col>grid[0].length-1 || grid[row][col]=='0'){
            return;
        }
        // 如果1的周围有1变成0
        grid[row][col]='0';
        dfs(grid, row-1, col);
        dfs(grid, row+1, col);
        dfs(grid, row, col-1);
        dfs(grid, row, col+1);
    }

}